using System;

namespace PDO.Utilities
{
    /// <summary>
    /// Infrastructure class to provide assertion support on boolean conditions, nulls and empty strings
    /// </summary>
    public static class Assert
    {
        #region [Constants]
        const string generalErrorMessage = "Error occured";
        #endregion

        #region Public Methods
        /// <summary>
        /// Checks if the variable is true or false, throws an exception if the variable is false
        /// </summary>
        /// <param name="condition">variable to be checked</param>
        static public void IsTrue(bool condition)
        {
            if (!condition)
            {
                throw new BasePDOException(generalErrorMessage);
            }
        }



        /// <summary>
        /// Checks if the variable is true or false, throws an exception with specified message if the variable is false
        /// </summary>
        /// <param name="condition">variable to be checked</param>
        /// <param name="message">Message to be shown on exception</param>
        static public void IsTrue(bool condition, String message)
        {
            IsNotNull(message);

            if (!condition)
            {
                throw new BasePDOException(message);
            }
        }

        /// <summary>
        /// Checks if the variable is true or false, throws an exception if the variable is true
        /// </summary>
        /// <param name="condition">variable to be checked</param>
        static public void IsFalse(bool condition)
        {
            if (condition)
            {
                throw new BasePDOException(generalErrorMessage);
            }
        }



        /// <summary>
        /// Checks if the variable is true or false, throws an exception with specified message if the variable is true
        /// </summary>
        /// <param name="condition">variable to be checked</param>
        /// <param name="message">Message to be shown on exception</param>
        static public void IsFalse(bool condition, String message)
        {
            IsNotNull(message);

            if (condition)
            {
                throw new BasePDOException(message);
            }
        }



        /// <summary>
        /// Checks to see if the two strings are equal and throws an exception if not
        /// </summary>
        /// <param name="stringExpected">what the string should be</param>
        /// <param name="stringActual">what the string actually is</param>
        static public void AreEqual(String expected, String actual)
        {
            IsNotNull(expected);

            IsNotNull(actual);

            if ((expected.CompareTo(actual)) != 0)
            {
                throw new BasePDOException(generalErrorMessage);
            }
        }



        /// <summary>
        ///  Checks to see if the two strings are equal and throws an exception if not
        /// </summary>
        /// <param name="stringExpected"></param>
        /// <param name="stringActual"></param>
        /// <param name="message"></param>
        static public void AreEqual(String expected, String actual, String message)
        {
            IsNotNull(expected);

            IsNotNull(actual);

            IsNotNull(message);

            if ((expected.CompareTo(actual)) != 0)
            {
                throw new BasePDOException(message);
            }
        }



        /// <summary>
        /// Checks to see if the two strings are not equal and throws an exception if they are equal
        /// </summary>
        /// <param name="stringExpected">what the string should be</param>
        /// <param name="stringActual">what the string actually contains</param>
        static public void AreNotEqual(String expected, String actual)
        {
            IsNotNull(expected);

            IsNotNull(actual);

            if ((expected.CompareTo(actual)) == 0)
            {
                throw new BasePDOException(generalErrorMessage);
            }
        }



        /// <summary>
        /// Checks to see if the two strings are not equal and throws an exception if they are equal
        /// </summary>
        /// <param name="stringExpected"></param>
        /// <param name="stringActual"></param>
        /// <param name="message"></param>
        static public void AreNotEqual(String expected, String actual, String message)
        {

            IsNotNull(expected);

            IsNotNull(actual);

            IsNotNull(message);

            if ((expected.CompareTo(actual)) == 0)
            {
                throw new BasePDOException(message);
            }
        }



        /// <summary>
        /// checks to see if the object is null
        /// </summary>
        /// <param name="objectToBeChecked">Object to be checked for null value</param>
        static public void IsNull(Object sender)
        {

            if (sender != null)
            {
                throw new BasePDOException(generalErrorMessage);
            }

        }



        /// <summary>
        /// checks to see if the object is Not null
        /// </summary>
        /// <param name="objectToBeChecked">Object to be checked for null value</param>
        static public void IsNotNull(Object sender)
        {

            if (sender == null)
            {
                throw new BasePDOException(generalErrorMessage);
            }

        }

        /// <summary>
        /// checks to see if the object is Not null with error message
        /// </summary>
        /// <param name="objectToBeChecked"></param>
        /// <param name="message"></param>
        static public void IsNotNull(Object sender, string message)
        {

            if (sender == null)
            {
                throw new BasePDOException(message);
            }

        }



        /// <summary>
        /// checks to see if the string is empty, if not empty throws an exception
        /// </summary>
        /// <param name="stringToBeChecked"></param>
        static public void IsEmpty(String parameter)
        {
            IsNotNull(parameter);

            if ((parameter.CompareTo(String.Empty)) != 0)
            {
                throw new BasePDOException(generalErrorMessage);
            }

        }



        /// <summary>
        /// checks to see if the string is empty, if not empty throws an exception with specified message
        /// </summary>
        /// <param name="stringToBeChecked">string to be checked for emptyness</param>
        /// <param name="message">Message to be shown on exception</param>
        static public void IsEmpty(String parameter, String message)
        {

            IsNotNull(parameter);

            IsNotNull(message);

            if ((parameter.CompareTo(String.Empty)) != 0)
            {
                throw new BasePDOException(message);
            }

        }



        /// <summary>
        /// checks to see if the string is Not empty, if empty throws an exception
        /// </summary>
        /// <param name="stringToBeChecked"></param>
        static public void IsNotEmpty(String parameter)
        {

            IsNotNull(parameter);

            if ((parameter.CompareTo(String.Empty)) == 0)
            {
                throw new BasePDOException(generalErrorMessage);
            }

        }



        /// <summary>
        /// checks to see if the string is Not empty, if empty throws an exception with specified message
        /// </summary>
        /// <param name="stringToBeChecked">string to be checked for emptyness</param>
        /// <param name="message">Message to be shown on exception</param>
        static public void IsNotEmpty(String parameter, String message)
        {

            IsNotNull(parameter);

            IsNotNull(message);

            if ((parameter.CompareTo(String.Empty)) == 0)
            {
                throw new BasePDOException(message);
            }

        }

        #endregion[Public Method]

    }
}